//
//  FSSpecialTopicViewController.m
//  fanshu
//
//  Created by mh on 16/3/27.
//  Copyright © 2016年 FS. All rights reserved.
//

#import "FSSpecialTopicViewController.h"

#import "FSDiscoverSpecialModel.h"
#import "FSDiscoverSpecialCell.h"
@interface FSSpecialTopicViewController ()
@property(nonatomic,strong)UIView *createdSpecialView;
@end

@implementation FSSpecialTopicViewController
#pragma mark - 属性懒加载
- (UIView *)createdSpecialView{
    if (_createdSpecialView == nil) {
        _createdSpecialView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 44)];
        UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(10, 4, ScreenWidth - 20, 40)];
        [btn setImage:@"button_artical_add_green" andHighlightedImage:@"button_artical_add"];
        [btn setBackgroundImage:[UIImage resizableImageWithImageName:@"button_green_lined"] forState:UIControlStateNormal];
        [btn setBackgroundImage:[UIImage resizableImageWithImageName:@"button_grey_lined"] forState:UIControlStateHighlighted];
        [btn setTitle:@"创建新专题" forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(createdBtnOnClick) forControlEvents:UIControlEventTouchUpInside];
        btn.titleLabel.font = setFont(13.0f);
        [_createdSpecialView addSubview:btn];
    }
    return _createdSpecialView;
}

- (void)createdBtnOnClick{
    NSLog(@"创建新专题");
}

#pragma  mark - 系统方法
- (void)viewDidLoad {
    [super viewDidLoad];
    //添加模型数组
    [self addModel];
    //设置创建新专题按钮
    [self setcreatedSpecialView];
}

#pragma  mark - 初始化方法
   //设置创建新专题按钮
- (void)setcreatedSpecialView{
    [UIView animateWithDuration:0.3f animations:^{
        self.tableView.tableHeaderView = self.createdSpecialView;
    }];
}

//子导航条按钮点击
- (void)setScrollerToolBar:(FSScrollerToolBar *)scrollerToolBar{
    [super setScrollerToolBar:scrollerToolBar];
    self.scrollerToolBar.btnOnClick = ^(FSButton *btn){
        if (![btn.titleLabel.text isEqualToString:@"热门"]) {
            self.tableView.tableHeaderView = nil;
        }else{
            self.tableView.tableHeaderView = self.createdSpecialView;
        }
    };
}

//添加模型数组
- (void)addModel{
    FSDiscoverSpecialModel *model = [[FSDiscoverSpecialModel alloc] init];
    model.icon = @"button_red_edit";
    model.special = @"番薯";
    model.countOfArticle = @"998";
    model.attented = NO;
    model.introduction = @"发来看时间的发货；拉很多事；富利卡接收到；风景好的；空间就会拉快点就反对的发货；拉很多事；富利卡接收到；风景好的；空间就会拉快点就反对的发货；拉很多事；富利卡接收到；风景好的；空间就会拉快点就反对的发货；拉很多事；富利卡接收到；风景好的；空间就会拉快点就反对的发货；拉很多事；富利卡接收到；风景好的；空间就会拉快点就反对的发货；拉很多事；富利卡接收到；风景好的；空间就会拉快点就反对的发货；拉很多事；富利卡接收到；风景好的；空间就会拉快点就反对浪费红开";
    model.countOfAttented = @"123";
    [self.dataArray addObject:model];
    [self.dataArray addObject:model];
    [self.dataArray addObject:model];
    [self.dataArray addObject:model];
    [self.dataArray addObject:model];
    [self.dataArray addObject:model];
    [self.dataArray addObject:model];
}

#pragma mark - TableView dataSourse
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *ID = @"discoverCell";
    FSDiscoverSpecialCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[FSDiscoverSpecialCell alloc] initWithStyle: UITableViewCellStyleSubtitle reuseIdentifier:ID];
    }
    FSDiscoverSpecialModel *model = self.dataArray[indexPath.row];
    cell.model = model;
    // 三个方法并用，就可以实现自定义分割线效果
    UIEdgeInsets insets = UIEdgeInsetsMake(0, 0, 0, 0);
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        //分割线的frame
        cell.separatorInset = insets;
    }
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        //cell被遮挡的范围
        [cell setLayoutMargins:insets];
    }
    if([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]){
        //是否保持父视图的遮挡布局？？？
        [cell setPreservesSuperviewLayoutMargins:NO];
    }
    return cell;
}
@end
